package com.search.es.controller;

import com.search.es.pojo.Goods;
import com.search.es.repository.GoodsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class EGoodsController {

    @Autowired
    private GoodsRepository goodsRepository;

    @RequestMapping("/save")
    public String save(){
        Goods goods = new Goods(2,"方便面",4.5);

        goodsRepository.save(goods);
        return "success";
    }
    @RequestMapping("/find/{id}")
    public Object findById(@PathVariable("id")Integer id){
      return   goodsRepository.findById(id);

    }
    @RequestMapping("/list")
    public Object list(){
      return   goodsRepository.findAll();

    }
    @RequestMapping("/remove/{id}")
    public Object remove(@PathVariable("id")Integer id){
        goodsRepository.deleteById(id);
        return "has deleted";
    }



}
